<template>
  <div>
    <NavBar :title="title" />
    <div class="content-top">
      <van-field required v-model="postData.license_NameValue" size="large" label="证书名称" maxlength="50" placeholder="请填写" style="font-size: 16px" />

      <van-field required readonly clickable size="large" :value="postData.date_Time" label="获得时间" placeholder="请选择" style="font-size: 16px" @click="showPicker_date = true" />
      <van-popup v-model="showPicker_date" round position="bottom">
        <van-datetime-picker v-model="picker_date_current" :min-date="picker_date_minDate" :max-date="picker_date_maxDate" type="year-month" title="获得时间" @confirm="onPickerDateSubmit" @cancel="showPicker_date = false" />
      </van-popup>

      <div style="margin: 16px">
        <van-button type="primary" block color="#05A6F0" round style="font-size: 18px" text="提交" :loading="loading_submit" :disabled="disabled_submit" @click="onSubmit">
        </van-button>
      </div>
    </div>
  </div>
</template>

<script>
import NavBar from '@/components/NavBar.vue'
import { Field, Popup, Button, Toast, DatetimePicker } from 'vant';
import { mixin_person_resumeSumbitBack } from '@/mixin/mixins'
import Global from '@/Global';
export default {
  name: 'ResumeZS',
  components: {
    NavBar,
    [Field.name]: Field,
    [Popup.name]: Popup,
    [Button.name]: Button,
    [DatetimePicker.name]: DatetimePicker,
  },
  props: ['title', 'data'],
  mixins: [mixin_person_resumeSumbitBack],
  mounted() {
		this.postData.id = this.$route.params.data ? this.$route.params.data.id : 0;
		if(this.postData.id != 0){
			this.$api.get('/Resume/GetLicense',{id:this.postData.id}).then(res=>{
				if(res.success){
					this.postData.license_NameValue = res.response.license_NameValue;
					this.postData.date_Time = res.response.date_Time;
					this.picker_date_current = new Date(this.postData.date_Time.substring(0, 4), parseInt(this.postData.date_Time.substring(5, 7)) - 1, 1);
				}
			})
		}
  },
  // 定义属性
  data() {
    return {
      postData: {
        id: 0,
        license_NameValue: '',
        date_Time: ''
      },
      showPicker_date: false,
      picker_date_current: new Date(2000, 0, 1),
      picker_date_minDate: new Date(new Date().getFullYear() - 50, 0, 1),
      picker_date_maxDate: new Date(new Date().getFullYear() + 1, 0, 1),

      loading_submit: false,
    }
  },
  computed: {
    disabled_submit() {
      if (this.postData.license_NameValue != '' && this.postData.date_Time != '')
        return false;
      return true;
    }
  },
  // 方法集合
  methods: {
    onPickerDateSubmit(value) {
      this.showPicker_date = false;
      this.postData.date_Time = this.$dayjs(value).format('YYYY/MM');
    },
    //提交
    onSubmit() {
      this.loading_submit = true;
			this.$api.post('/Resume/SaveLicense',this.postData).then(res=>{
				this.loading_submit = false;
				if(res.success){
					Toast.success('保存成功');
					this.$bus.$emit(Global.bus_person_resume_update, 'ok');
					this.goBack();
				}
				else{Toast.fail(res.msg)}
			})
    }
  },
}
</script>

<style scoped>
</style>